package me.softwareengineer.guice.rendering.domain.referenece;

import org.apache.commons.lang3.StringUtils;

/**
 * Represents a reference to an external wiki(<a
 * href="http://en.wikipedia.org/wiki/InterWiki">Inter Wiki</a>). Interwiki
 * linking is, a facility for creating links to the many wikis on the World Wide
 * Web. Users avoid pasting in entire URLs (as they would for regular web pages)
 * and instead use a shorthand similar to links within the same wiki (intrawiki
 * links).
 * 
 * @author yadtahir
 * 
 */
public class InterwikiResourceReference extends ResourceReference {

	/**
	 * The name of the parameter representing the InterWiki Alias.
	 */
	private static final String INTERWIKI_ALIAS = "interWikiAlias";

	/**
	 * Create an interwiki reference
	 * 
	 * @param reference
	 *            the refenece of the interwiki
	 */
	public InterwikiResourceReference(String reference) {
		super(reference, ResourceType.INTERWIKI);
	}

	/**
	 * @return the <a href="http://en.wikipedia.org/wiki/InterWiki">Inter
	 *         Wiki</a> alias to which the resource is pointing to or null if
	 *         not defined. Mappings between Inter Wiki aliases and actual
	 *         locations are defined in the Inter Wiki Map. Example: "wikipedia"
	 */
	public String getInterWikiAlias() {
		return (String) getMetaData(INTERWIKI_ALIAS);
	}

	/**
	 * @param interWikiAlias
	 *            see {@link #getInterWikiAlias()}
	 */
	public void setInterWikiAlias(String interWikiAlias) {
		if (!StringUtils.isEmpty(interWikiAlias))
			addMetaData(INTERWIKI_ALIAS, interWikiAlias);
	}
}
